<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资源管理</title>
 <%@ include file="/WEB-INF/page/public/contentmeta.jsp"%>
  <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
   <link rel="stylesheet" href="/css/global.css" media="all" />
    <link rel="stylesheet" href="/css/tab.css" media="all" />
</head>
<body>

<div class="admin-tab admin-user">

	<form class="clefix"  action="/systerm/getSystermlist" method="post" id="sysform">
		<div class="layui-form-item">
			<input name="skipToPage" id="skipToPage"  type="hidden" value="${pager.pageNo}">
			<input type="hidden" id="pageNo" name="pageNo" value="${pager.pageNo}">
			<input type="hidden" id="totalPage" name="totalPage" value="${pager.totalPages}">
			<input type="hidden" id="pid" name="pid" value="${pid}">
		</div>
	</form>

    <div class="tab-condition">
        
        <div class="TM-tab-info">
        	<c:if test="${pid != null && pid > 0 }">
        		<a href="javascript:history.go(-1);" class="layui-btn layui-btn-primary layui-btn-small"><i class="layui-icon">&#xe603;</i>返回</a>
        	</c:if>
            <a class="layui-btn layui-btn-primary layui-btn-small active termadd">+资源添加</a>
        </div>
    </div>
 
    <div class="layui-field-box">
        <table class="site-table table-hover TM-user">
            <thead>
            <tr>
                <th style="width:10%;">功能名称</th>
                <th style="width:15%;">功能URL</th>
                <th style="width:10%;">功能父类</th>
                <th style="width:15%;">备注</th>
                <th style="width:10%;">排序号</th>
                <th style="width:10%;">创建时间</th>
                <th style="width:10%;">修改时间</th>
                <th style="width:10%;">修改人</th> 
                <th style="width:10%;">操作</th>
            </tr>
            </thead>
            <tbody>
            	<c:forEach var="stlist" items="${pager.resultList}">
					<tr>
						<td><a href="/systerm/getSystermlist?pid=${stlist.id}">${stlist.name}</td>
						<td>${stlist.url}</td>
						<td>${stlist.pid}</td>
						<td>${stlist.remark}</td>
						<td>${stlist.ordernumber}</td>
						<td>${stlist.createdate}</td>
						<td>${stlist.updatedate}</td>
						<td>${stlist.updateuser}</td>
						  <td><button class="layui-btn layui-btn-primary layui-btn-small termedit" data="${stlist.id}"><i class="layui-icon "></i></button></td>
					</tr>
				</c:forEach>
              
            </tbody>
        </table>
        <div class="admin-table-page">
            <div id="page" class="page"></div> 
        </div>
    </div>
</div>


<!-- 添加角色 -->
<div class="layui-form-item" id="validateadd-formDiv" style="width:90%;margin-top:20px;display:none">
<form  class="layui-form clefix" action="/systerm/getSystermlist"  id="validateadd-form" method="post">
	<div class="layui-form-item">
	  <div class="layui-inline">
	    <label class="layui-form-label">功能名称</label>
	    <div class="layui-input-inline" style="width: 120px;">
	      <input id="name" 	name="name" type="text" placeholder="" autocomplete="off" class="layui-input">
	       <input type="hidden" id="id1" name="id1" />
	    </div>
	     
	      <label class="layui-form-label">父类ID</label>
	    <div class="layui-input-inline" style="width: 120px;">
	      <input id="pid" name="pid" type="text"  value="${param.pid}" placeholder="" autocomplete="off" class="layui-input">
	    </div>
	    
	     <label class="layui-form-label">排序号</label>
	    <div class="layui-input-inline" style="width: 100px;">
	        <input  id="ordernumber"   name="ordernumber" type="text"  value="${param.ordernumber}" placeholder="" autocomplete="off" class="layui-input">
	         <input   name="reserve" type="hidden"  value="1" placeholder="" autocomplete="off" class="layui-input">
	    </div>
	  </div> 
	   <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">URL</label>
	    <div class="layui-input-block">	 
	        <input id="url" 	name="url" type="text" placeholder="" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">备注</label>
	    <div class="layui-input-block">	 
	      <textarea   placeholder="请输入内容"  id="remark" name="remark"   class="layui-textarea"></textarea>
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <div class="layui-input-block">
	      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
	      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
	    </div>
	  </div>  
	</div>
</form>
</div>
<!-- 添加菜单 -->

 


<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script>
    layui.config({
        base: '/plugins/layui/modules/'
    });
    layui.use(['icheck','element','laypage','form'], function() {
        var $ = layui.jquery,
              	laypage = layui.laypage,
                element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块
        var form = layui.form();
        $('input').iCheck({
            checkboxClass: 'icheckbox_flat-blue	'
        });
      
        var pageNo = $("#pageNo").val();
    	var totalPage = $("#totalPage").val(); 
        //page
        laypage({
            cont: 'page',
            curr: pageNo//'${pager.pageNo}'
            ,pages: totalPage//'${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#sysform").submit();
                }
            }
        });
        
        
        $('.termadd').on('click', function() {
        	$('#validateadd-form').trigger("reset")  
			layer.open({
				title: '添加资源',
				maxmin: true,
				type: 1,
				content:  $('#validateadd-formDiv'),
				area: ['900px', '450px']
			});
		});
        
        $(".termedit").on('click', function() {
    		var id = $(this).attr("data");
    		
    		updatecld({id:id})
    		layer.open({
				title: '修改资源',
				maxmin: true,
				type: 1,
				content:  $('#validateadd-formDiv'),
				area: ['900px', '450px']
			});
    	}); 
        
        
        $('.site-table tbody tr').on('click', function(event) {
            var $this = $(this);
            var $input = $this.children('td').eq(0).find('input');
//				$input.on('ifChecked', function(e) {
//					$this.css('background-color', '#pink');
//				});
            $input.on('ifUnchecked', function(e) {
                $this.removeAttr('style');
            });
            $input.iCheck('toggle');
        }).find('input').each(function() {
            var $this = $(this);
            $this.on('ifChecked', function(e) {
                $this.parents('.pink').css('background-color', '#f9eff1');
            });
            $this.on('ifChecked', function(e) {
                $this.parents('.yellow').css('background-color', '#f3fae3');
            });
            $this.on('ifUnchecked', function(e) {
                $this.parents('tr').removeAttr('style');
            });
        });
        $('#selected-all').on('ifChanged', function(event) {
            var $input = $('.site-table tbody tr td').find('input');
            $input.iCheck(event.currentTarget.checked ? 'check' : 'uncheck');
        });
    });
    
    
    
    $(function(){ 
   	 $("#validateadd-form").validate({
   		 rules: {
   		    	name: "required",
   		      },
   		      messages: {
   		    	  name: "请输入资源名称",
   		      },
   		      errorPlacement: function(error, element) {
				layer.tips(error.text(), element, {
					tips: [2,tipColor],
	       		 tipsMore: true
	       		});
	      	},     
   		 submitHandler: function(form) {
   			    var id = $("#id1").val();
   				var name = $("#name").val();
   				var url = $("#url").val();
   				var type = $("#type").val();
   				var pId = $("#pid").val();
   				var remark = $("#remark").val();
   				var reserve = $("#reserve").val();
   				var ordernumber = $("#ordernumber").val();
   				if(!/^[0-9]*$/.test(type)){  
   				  layer.msg("功能类型只能为数字！");  
   			    }
   				var ajxurl = "/systerm/savesysterm";
   				var msg ="添加";
   				if(id.length>0){ 
   					ajxurl = "/systerm/updatesysterm";
   					msg ="修改";
   				}
   				
   				$.ajax({
   					type : "POST",
   					url : ajxurl,
   					data : {
   						id:id,
   						name : name,
   						url : url,
   						type : type,
   						pid : pId,
   						remark : remark,
   						reserve : reserve,
   						ordernumber:ordernumber
   					},
   					dataType : "json",
   					success : function(data) {
   						if (data == 0) {
   						  layer.msg(msg+"失败!");
   						} else {
   						  layer.msg(msg+"成功!", {icon: 1},function(){
  					    	   window.location.href="/systerm/getSystermlist?pid=0";
 					    	});
   						}
   					}
   				}); 
   	      } 
   	    });  
   });   
 
 
   function updatecld(f) {
   	$.ajax({
   		type : "POST",
   		url : "/systerm/getsystermbyid",
   		data : {
   			
   			id : f.id
   		},
   		dataType : "json",
   		success : function(data) {
   			$('#validateadd-form').trigger("reset") ;
   			$("#id1").val(f.id);
   			$("#name").val(data.title);
   			$("#url").val(data.href);
   			$("#type").val(data.type);
   			$("#pid").val(data.pid);
   			$("#ordernumber").val(data.ordernumber);
   			$("#remark").val(data.icon);
   			$("#reserve").val(data.reserve);
   			
   		}
   		
   	}); 
   }

</script>
 
</body>

</html>